import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;

import java.util.Properties;

public class NacosClient {

    public static void main(String[] args) throws NacosException {
        Properties properties = new Properties();
        // 指定配置的 DataID 和 Group
        String dataId = "manager.yaml";
        String group = "MANAGER_GROUP";
        String content = "extend:\n" +
                "    message: Extend Message2";
        properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848");
        // 从控制台命名空间管理的"命名空间详情"中拷贝 endpoint、namespace
//        properties.put(PropertyKeyConst.ENDPOINT, "8a21d2a7-9933-47c4-8f2b-60379d1e72ff");
        properties.put(PropertyKeyConst.NAMESPACE, "8a21d2a7-9933-47c4-8f2b-60379d1e72ff");
        // 通过 ECS 实例 RAM 角色访问 ACM
        // properties.put("ramRoleName", "$ramRoleName");
//        properties.put(PropertyKeyConst.ACCESS_KEY, "${accessKey}");
//        properties.put(PropertyKeyConst.SECRET_KEY, "${secretKey}");
        ConfigService configService = NacosFactory.createConfigService(properties);
        // 发布配置
        boolean publishConfig = configService.publishConfig(dataId, group, content);
        System.out.println(publishConfig);
    }
}
